package com.lbb.springboot.util;

import com.lbb.springboot.entity.dto.GpsInstallOrderDetails;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author likanghong
 */
public class DataUtils {
    public static List<Map<Integer, String>> getGpsExData(
            List<GpsInstallOrderDetails> list) {
        List<Map<Integer, String>> rows = new LinkedList<>();         // 数据
//        年份	月份	下单日期	行驶证名称	下单源	车架号	车牌号
// 	设备类型	年限	客户经理
// 安装师傅	安装完成时间	设备号	SIM卡号	应收费用	应收年费	 收款日期	 收入金额 	 收支差异 	收款方式	收款情况
        for (GpsInstallOrderDetails gpsInstallOrderDetails : list) {
            Integer index = 0;
            Map<Integer, String> map = new LinkedHashMap<>();
            map.put(index++, DateUtil.dateTo0String(gpsInstallOrderDetails.getCreateDate(), DateUtil.FORMAT_YEAR)); // 年份
            map.put(index++, DateUtil.dateTo0String(gpsInstallOrderDetails.getCreateDate(), DateUtil.FORMAT_MONTH));//月份
            map.put(index++, DateUtil.dateTo0String(gpsInstallOrderDetails.getCreateDate(), DateUtil.FORMAT_NORMAL));//下单日期
            map.put(index++, gpsInstallOrderDetails.getCompanyName()); //行驶证名称
            map.put(index++, gpsInstallOrderDetails.getFleetName());//下单源
            map.put(index++, gpsInstallOrderDetails.getDframeNumber());//车架号
            map.put(index++, gpsInstallOrderDetails.getDlicensePlateNumber());//车牌号
            String deviceType = null;
            if ("1".equals(gpsInstallOrderDetails.getDeviceType())) {
                deviceType = "30G";
            } else {
                deviceType = "30E";
            }
            map.put(index++, deviceType);//设备类型

            map.put(index++, gpsInstallOrderDetails.getReserveYear() + "");//年限
            map.put(index++, gpsInstallOrderDetails.getSaleName() + "");//客户经理
            map.put(index++, gpsInstallOrderDetails.getAdminName() + "");//安装师傅
            map.put(index++, DateUtil.dateTo0String(gpsInstallOrderDetails.getDcreateDate(), DateUtil.FORMAT_NORMAL));//安装完成时间
            map.put(index++, gpsInstallOrderDetails.getDeviceId() + "");//设备号
            map.put(index++, gpsInstallOrderDetails.getSimCode() + "");//SIM卡号
            map.put(index++, gpsInstallOrderDetails.getUnitPrice() + "");//应收费用
            map.put(index++, gpsInstallOrderDetails.getYearAount() + "");//应收年费

            if (gpsInstallOrderDetails.getReceiptDate() != null) {
                map.put(index++, DateUtil.dateTo0String(gpsInstallOrderDetails.getReceiptDate(), DateUtil.FORMAT_NORMAL));//收款日期
            } else {
                map.put(index++, "无收款");
            }
            map.put(index++, gpsInstallOrderDetails.getTotalAcount() + "");//收入金额
            map.put(index++, gpsInstallOrderDetails.getUnitPrice().subtract(gpsInstallOrderDetails.getTotalAcount()) + "");//收支差异

            String receiptType = null;
            if (gpsInstallOrderDetails.getReceiptType() == null) {
                receiptType = "未收款";
            } else if (gpsInstallOrderDetails.getReceiptType() == 1) {
                receiptType = "旭利849";
            } else if (gpsInstallOrderDetails.getReceiptType() == 2) {
                receiptType = "北斗688";
            } else if (gpsInstallOrderDetails.getReceiptType() == 3) {
                receiptType = "农行678";
            } else if (gpsInstallOrderDetails.getReceiptType() == 4) {
                receiptType = "现金";
            } else if (gpsInstallOrderDetails.getReceiptType() == 5) {
                receiptType = "夏生";
            } else if (gpsInstallOrderDetails.getReceiptType() == 6) {
                receiptType = "师傅代收";
            } else if (gpsInstallOrderDetails.getReceiptType() == 7) {
                receiptType = "微信支付";
            } else if (gpsInstallOrderDetails.getReceiptType() == 8) {
                receiptType = "卡币支付";
            }
            map.put(index++, receiptType);//收款方式
            String bills = "";
            if (gpsInstallOrderDetails.getReceiptStatus() == null) {
                gpsInstallOrderDetails.setReceiptStatus(1);
            }
//            收款状态1 待收款  2  已收款  3 未收完
            if (gpsInstallOrderDetails.getReceiptStatus() == 1) {
                bills = "未收款";
            }
            if (gpsInstallOrderDetails.getReceiptStatus() == 2) {
                bills = "已收款";
            }
            if (gpsInstallOrderDetails.getReceiptStatus() == 3) {
                bills = "未收清";
            }
            map.put(index++, bills);//收款情况
            rows.add(map);
        }
        return rows;
    }
}
